﻿#region 命名空间

using System;
using System.Web.Mvc;
using Ext.Net;

#endregion

namespace Sharp.Web
{
    public static class HtmlHelperExtension
    {
    }

    public static class BuilderExtension
    {
        /// <summary>
        ///     加载预设默认设置
        /// </summary>
        /// <param name="helper"></param>
        /// <returns></returns>
        public static FormPanel.Builder Default(this FormPanel.Builder helper)
        {
            var panel = helper.FieldDefaults(fd =>
            {
                fd.LabelSeparator = "：";
                fd.LabelWidth = 110;
                fd.LabelAlign = LabelAlign.Right;
                //fd.InputWidth = 220;
            });

            return panel.BodyPadding(5);
        }

        public static DropDownField.Builder OrgList(this DropDownField.Builder helper, Node orgTree,string valueHiddenName="OrgId")
        {
            var x = Html.X();
            var id = "field" + Guid.NewGuid();
            id = id.Replace("-", "");

            var dropdownlist = helper.ID(id).ValueHiddenName(valueHiddenName).Mode(DropDownMode.ValueText).Component(c => c.Add(
                x.TreePanel()
                    .Root(orgTree)
                    .RootVisible(false)
                    .Listeners(li => li.ItemClick.Handler = "App.Edit.SetDropdownList(#{" + id + "},record);")
                    .Buttons(x.Button().Text("关闭").ClickEvent("#{" + id + "}.collapse();"))
                ));
            return dropdownlist;
        }

    }
}